
import requests

url = 'https://edith.xiaohongshu.com/api/sns/web/v2/comment/page?note_id=6489a287000000001203341c&cursor=&top_comment_id=&image_formats=jpg,webp,avif&xsec_token=ABZH_BdY1F9nby0pBgFe8-o2BVHPLKA3t6fKnBtroJvf4%3D'

headers = {
    'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36',
    'cookie':'abRequestId=e265a05b-cff5-57c2-8550-8644fa4e8fb3; webBuild=4.84.4; a1=19a5436f3c8kjd9i6m1uz1913o7vcl499w3w3spva50000241080; webId=67f93245b9ba17bcbb273712f9ced3b1; web_session=030037ae3805d3a0bc1eeb17732e4aa5e7cd5b; gid=yj024qW8yJj2yj024qKiqEMUSYTVfj3K6y7uqh0yjyqlWE28hS14jq888J4y8Y88YyyqDW2D; websectiga=29098a4cf41f76ee3f8db19051aaa60c0fc7c5e305572fec762da32d457d76ae; sec_poison_id=07336858-26af-4b11-ae50-70d77932287f; xsecappid=xhs-pc-web; acw_tc=0ad528dd17625194753986031ed29a884ad00023c8251c6307d9d6005d3ed9; unread={%22ub%22:%226909ceb7000000000302fc52%22%2C%22ue%22:%2268e7aafd00000000040112d5%22%2C%22uc%22:24}; loadts=1762519523627',
}

response = requests.get(url, headers=headers)
# print(response.status_code)
# print(response.text)
# {'note_id': '6489a287000000001203341c', 'content': '可以带儿童护肤吗', 'create_time': 1686743072000, 'status': 0, 'at_users': [], 'show_tags': [], 'sub_comments': [{'note_id': '6489a287000000001203341c', 'status': 0, 'at_users': [], 'show_tags': ['is_author'], 'target_comment': {'id': '6489a820000000002a00affb', 'user_info': {'user_id': '57e23d286a6a691652d09b03', 'nickname': 'VICKEY', 'image': 'https://sns-avatar-qc.xhscdn.com/avatar/1040g2jo30nsbcgkf1c6048n2cauih6o3ltecfj8?imageView2/2/w/120/format/jpg', 'xsec_token': 'ABlf__lK8roP8hbFfmcQ8rSlxzN1iLaDJ7AqldEPrYzig='}}, 'id': '6489adb00000000018005e50', 'content': '保宁好像在国内也很受宝妈妈喜欢，这个国内可以买到哦！[偷笑R]', 'liked': False, 'like_count': '1', 'user_info': {'user_id': '55f8bfb0e4b1cf115350809a', 'nickname': '中韩家庭番茄家', 'image': 'https://sns-avatar-qc.xhscdn.com/avatar/62ad419538005188750079b0.jpg?imageView2/2/w/120/format/jpg', 'xsec_token': 'AB9bEjsGKJ-ZMger8wmfdHNus0_aqMf1ZSV6gTUwau-Eg='}, 'create_time': 1686744496000}], 'id': '6489a820000000002a00affb', 'like_count': '2', 'sub_comment_count': '4', 'sub_comment_cursor': '6489adb00000000018005e50', 'sub_comment_has_more': True, 'liked': False, 'user_info': {'user_id': '57e23d286a6a691652d09b03', 'nickname': 'VICKEY', 'image': 'https://sns-avatar-qc.xhscdn.com/avatar/1040g2jo30nsbcgkf1c6048n2cauih6o3ltecfj8?imageView2/2/w/120/format/jpg', }}
if response.status_code == 200:
    json_data = response.json()['data']
    items = json_data['comments']
    for item in items:
        # print(item['content'])
        # print(item)
        first_comment = item['content']
        # print(first_comment)
        for sub_comment in item['sub_comments']:
            # print(sub_comment)
            # print(sub_comment['target_comment']['user_info'])
            # print(sub_comment['user_info']['nickname'])
            # print(sub_comment['content'])
            dit = {
                '评论人昵称':sub_comment['target_comment']['user_info']['nickname'],
                '评论内容': first_comment,
                '回复内容': sub_comment['content'],
                '评论人头像url':sub_comment['target_comment']['user_info']['image'],

            }
            print(dit)

